package com.ipDev.moyvSys.controller.emp;


import com.ipDev.moyvSys.domain.dto.PageDTO;
import com.ipDev.moyvSys.domain.dto.ProblemDTO;

import com.ipDev.moyvSys.domain.dto.ProblemPageQueryDTO;
import com.ipDev.moyvSys.domain.vo.ProblemVO;
import com.ipDev.moyvSys.service.IProblemService;
import com.ipDev.moyvSys.utils.Result;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 题目表 前端控制器
 * </p>
 *
 * @author fish
 * @since 2024-10-22
 */
@RestController
@RequestMapping("/emp/problem")
@Slf4j
@RequiredArgsConstructor
@Api(value = "职工的问题相关接口")
public class EmpProblemController {

    private final IProblemService problemService;


    @PostMapping
    public Result<Void> saveOne(@RequestBody ProblemDTO dto) {
        log.info("新增单个问题:{}", dto);
        problemService.saveOne(dto);
        return Result.success("finished");
    }

    @PostMapping("/batchSave")
    public Result<Void> batchSave(@RequestBody List<ProblemDTO> list) {
        log.info("批量新增问题:{}", list);
        for (ProblemDTO dto : list) {
            saveOne(dto);
        }
        return Result.success("finished");
    }

    @DeleteMapping("/del/{id}")
    public Result<Void> delProblem(@PathVariable Integer id) {
        log.info("删除问题:{}", id);
        //TODO 删除的同时要删除和选项的相关数据
        problemService.delProblem(id);
        return Result.success("finished");
    }

    @DeleteMapping("/del")
    public Result<Void> delProblemBatch(@RequestBody List<Integer> list) {
        log.info("批量删除:{}", list);
        problemService.delProblemBatch(list);
        return Result.success("finished");
    }

    @PutMapping("/update")
    public Result<Void> updateProblem(@RequestBody ProblemDTO dto) {
        log.info("更新问题:{}", dto);
        problemService.updateProblem(dto);
        return Result.success("finished");
    }

    @GetMapping("/page")
    public Result<PageDTO<ProblemVO>> page(@RequestBody ProblemPageQueryDTO dto) {
        //根据某种信息筛选问题分页查询
        log.info("分页查询:{}", dto);
        return Result.success(problemService.queryProblemByPage(dto));
    }

}
